#ifndef MYTHREAD_H
#define MYTHREAD_H

#include <QObject>
#include <QThread>
#include <QReadWriteLock>
#include <QTcpSocket>
#include <QTimer>
#include "session.h"

/*
    自定义的类加上 Q_OBJECT 就报错的解决方法是
    在“构建”菜单栏中选择“重新构建所有项目”
*/

enum tcpMsgType{UserEnter,UserLeft,KeepAlivePacket};

class MyThread : public QThread
{
Q_OBJECT
public:
    MyThread(qintptr socketDescriptor,QObject *parent=nullptr);

    ~MyThread() = default;

protected:
    void run();

private slots:
    void onReadyRead();  // 声明 onReadyRead() 槽函数

    void removeItem(const QString &item);

signals:
    void updateListItem();

    void closeThread(MyThread *thread);    // 关闭一个线程

private:
    bool killThread = false;    // 是否杀死当前线程;false 表示不杀死

    QTcpSocket *socket;

    QString currentItem;

    Session *aSession;   // 一个会话

    QTimer *timer;

};

#endif // MYTHREAD_H
